/**
 * 流程定义
 */
layui.config({
  base: '/'
}).extend({
  flying: 'flying'
}).define(['index', 'flying'], function (exports) {  //先加载index模块，里面配置了全局的入口
  let admin = layui.admin;
  let flying = layui.flying;
  let form = layui.form;
  let table = layui.table;
  let layer = layui.layer;
  let dropdown = layui.dropdown;

  flying.table({
    elem: '#LAY-deployment-table',
    url: '/process/getProcessDefinitionPageList', //数据接口
    cols: [
      {type: 'checkbox', fixed: 'left'}
      , {type: 'numbers', fixed: 'left', title: '序号'}
      , {field: 'id', title: '流程定义ID', minWidth: 120}
      , {field: 'deploymentId', title: '部署ID', minWidth: 90}
      , {field: 'key', title: '流程定义KEY', minWidth: 100}
      , {field: 'name', title: '流程名称', minWidth: 100}
      , {field: 'resource', title: '资源资源', minWidth: 120}
      , {field: 'suspended', title: '状态', minWidth: 80, templet: function (d) {
          if (d.suspended == false) {
            return '<span class="layui-bg-blue layui-badge-rim">激活</span>';
          } else if (d.suspended == true) {
            return '<span class="layui-badge layui-badge-rim">挂起</span>';
          } else {
            return '';
          }
        }, unresize: true}
      , {field: 'version', title: '版本号', minWidth: 50, unresize: true}
      , {field: 'diagramResourceName', title: '流程图', minWidth: 100}
      , {field: 'tenantId', title: '租户号', minWidth: 90}
      // , {title: '操作', width: 160, align: 'center', fixed: 'right', toolbar: '#deployment-table'}
    ]
  });

  //监听工具条
  table.on('tool(LAY-deployment-table)', function (obj) {
    let line_data = obj.data;
    if (obj.event === 'pic') {

    } else if (obj.event === 'more') {
      //下拉菜单
      dropdown.render({
        elem: this, // 触发事件的 DOM 对象
        show: true, // 外部事件触发即显示
        align: 'left ' , // 右对齐弹出
        data: [
          {
            title: '激活',
            id: 'active',
            templet: '<i class="layui-icon layui-icon-ok"></i> {{= d.title}}',
            href: '#'
          },
          {
            title: '挂起',
            id: 'suspend',
            templet: '<i class="layui-icon layui-icon-close"></i> {{= d.title}}',
            href: '#'
          },
          {
            title: "删除",
            id: "del",
            templet: '<i class="layui-icon layui-icon-delete"></i> {{= d.title }}',
            href: '#'
          }
        ],
        click: function (mdata) {
          let processDefId = line_data.id;
          if (mdata.id === "active") {

          } else if (mdata.id === "suspend") {

          } else if (mdata.id === "del") {

          }
        }
      });
    }
  });

  //对外暴露的接口
  exports('deployment', {});
});

